package top.fangw.common.mybatis.config;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import com.github.f4b6a3.ulid.UlidCreator;
import org.springframework.stereotype.Component;

/**
 * @author fgw
 * @description 主键生成器
 * @createDate 2024/3/2
 */
@Component
public class CustomIdGenerator extends DefaultIdentifierGenerator {

    @Override
    public Long nextId(Object entity) {
        return super.nextId(entity);
    }

    @Override
    public String nextUUID(Object entity) {
        String string = UlidCreator.getUlid().toString();
        if (StrUtil.isNotBlank(string)) {
            return string.toLowerCase();
        }
        return super.nextUUID(entity);
    }
}